package com.example.jrfwcwgl.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.example.jrfwcwgl.entity.TJrProduct;
import com.example.jrfwcwgl.service.ITJrProductService;
import com.org.vo.ResultEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author yangsaiyu
 * @since 2021-11-23
 */
@RestController
@RequestMapping("/jrfwcwgl/product")
public class TJrProductController {
    @Autowired
    ITJrProductService itJrProductService;

    @RequestMapping("productTypeOne")
    public ResultEntity productTypeOne(){
        QueryWrapper<TJrProduct> wrapper = new QueryWrapper<>();
        wrapper.eq("jr_product_type",1);
        List<TJrProduct> list = itJrProductService.list(wrapper);
        return ResultEntity.ok(list);
    }

    @RequestMapping("productTypeTwo")
    public ResultEntity productTypeTwo(){
        QueryWrapper<TJrProduct> wrapper = new QueryWrapper<>();
        wrapper.eq("jr_product_type",2);
        List<TJrProduct> list = itJrProductService.list(wrapper);
        return ResultEntity.ok(list);
    }

    @RequestMapping("productTypeThree")
    public ResultEntity productTypeThree(){
        QueryWrapper<TJrProduct> wrapper = new QueryWrapper<>();
        wrapper.eq("jr_product_type",3);
        List<TJrProduct> list = itJrProductService.list(wrapper);
        return ResultEntity.ok(list);
    }

    @PostMapping("updateProduct")
    public ResultEntity updateProduct(@RequestBody TJrProduct product){
        boolean b = itJrProductService.updateById(product);
        if (b){
            return ResultEntity.error();
        }
        return ResultEntity.ok();
    }

    @RequestMapping("deleteProduct")
    public ResultEntity deleteProduct(Integer id){
        boolean b = itJrProductService.removeById(id);
        if (b){
            return ResultEntity.error();
        }
        return ResultEntity.ok();
    }

    @RequestMapping("updateDelFlagProduct")
    public ResultEntity updateDelFlagProduct(Integer id){
        UpdateWrapper<TJrProduct> tJrProductUpdateWrapper = new UpdateWrapper<>();
        tJrProductUpdateWrapper.set("del_flg",1);
        tJrProductUpdateWrapper.eq("id",id);
        boolean update = itJrProductService.update(tJrProductUpdateWrapper);
        if (update){
            return ResultEntity.error();
        }
        return ResultEntity.ok();
    }


}
